package com.firexxx.study.lock.task;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.firexxx.study.lock.monitor.JavaHeadParser;
import com.firexxx.study.performancetest.task.IFixedTimeConsumeTask;
import com.firexxx.study.performancetest.timeconsume.ITimeConsume;
import lombok.Data;

/**
 * TODO
 *
 * @author fireXXX
 * @date 2020/11/19 0:14
 **/
public class SyncConsumeTask extends IFixedTimeConsumeTask {

    private long count = 0;

    private void syncAdd() {
        Integer a = 1;
        synchronized (a) {
//            try {
//                System.out.println(JavaHeadParser.parse(SyncConsumeTask.class).toJson());
//            } catch (JsonProcessingException e) {
//                e.printStackTrace();
//            }
            getTimeConsume().run();
        }
    }

    @Override
    public Object runOne() {
        syncAdd();
        count++;

        return null;
    }

    @Override
    public void setCount(long count) {
        this.count = count;
    }

    @Override
    public long getCount() {
        return count;
    }

}